package com.sgb.kjwl.view.ui.adapter.self;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.businessmanagement.CompanyEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.List;

public class CompanyChangeAdapter extends BaseRecycleAdapter<CompanyEntity> {

    String no;
    Context context;

    public CompanyChangeAdapter(Context context, List<CompanyEntity> datas) {
        super(context, R.layout.item_self_company_change, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, CompanyEntity provinceEntity) {
        holder.setBinding(BR.viewModel, provinceEntity);
        TextView tv = holder.getItem().findViewById(R.id.company_name);
        ImageView logo = holder.getItem().findViewById(R.id.company_logo);
        TextView tag = holder.getItem().findViewById(R.id.company_tag);
        View horizontal_line = holder.getItem().findViewById(R.id.horizontal_line);
//        if(provinceEntity.getIsMainCompany().equals("1")){
//            holder.getItem().findViewById(R.id.company_select).setVisibility(View.VISIBLE);
//            tv.setTextColor(Color.parseColor("#0286DF"));
//            horizontal_line.setVisibility(View.GONE);
//        }else{
//            holder.getItem().findViewById(R.id.company_select).setVisibility(View.GONE);
//            tv.setTextColor(Color.parseColor("#666666"));
//        }
        no = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
        if (no != null && no.equals(provinceEntity.getCompNo())) {
            holder.getItem().findViewById(R.id.company_select).setVisibility(View.VISIBLE);
            tv.setTextColor(context.getResources().getColor(R.color.color_secondary_blue));
//            horizontal_line.setVisibility(View.GONE);
        } else {
            holder.getItem().findViewById(R.id.company_select).setVisibility(View.GONE);
            tv.setTextColor(context.getResources().getColor(R.color.color_title_medium));
        }


        RequestOptions optionsUser = new RequestOptions()
                .placeholder(R.mipmap.def_photo)//图片加载出来前，显示的图片
                .fallback(R.mipmap.def_photo)
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))//裁剪圆形
                .error(R.mipmap.def_photo);//图片加载失败后，显示的图片

        RequestOptions optionsCompany = new RequestOptions()
                .placeholder(R.mipmap.shop_img_new_2)//图片加载出来前，显示的图片
                .fallback(R.mipmap.shop_img_new_2) //url为空的时候,显示的图片
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))//裁剪正方形
                .error(R.mipmap.shop_img_new_2);//图片加载失败后，显示的图片

        RequestOptions optionsTeam = new RequestOptions()
                .placeholder(R.drawable.icon_team_default)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_team_default) //url为空的时候,显示的图片
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))//裁剪圆形
                .error(R.drawable.icon_team_default);//图片加载失败后，显示的图片

        RequestOptions optionsOrganization = new RequestOptions()
                .placeholder(R.drawable.icon_organization_default)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_organization_default) //url为空的时候,显示的图片
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))//裁剪圆形
                .error(R.drawable.icon_organization_default);//图片加载失败后，显示的图片

        if (provinceEntity.getType()==0) {
            Glide.with(context).load(provinceEntity.getCompLogo()).apply(optionsUser).into(logo);
            tag.setText("个人");
            tag.setTextColor(context.getResources().getColor(R.color.color_third_green_easy));
            tag.setBackground(context.getResources().getDrawable(R.drawable.green_text_radius2));
        } else if (provinceEntity.getType()==1){
            Glide.with(context).load(provinceEntity.getCompLogo()).apply(optionsCompany).into(logo);
            tag.setText("企业");
            tag.setTextColor(context.getResources().getColor(R.color.color_secondary_blue));
            tag.setBackground(context.getResources().getDrawable(R.drawable.blue_text_radius2));
        } else if (provinceEntity.getType() == 2){
            Glide.with(context).load(provinceEntity.getCompLogo()).apply(optionsTeam).into(logo);
            tag.setText("团队");
            tag.setTextColor(context.getResources().getColor(R.color.color_secondary_yellow_easy));
            tag.setBackground(context.getResources().getDrawable(R.drawable.orange_text_radius2));
        } else {
            Glide.with(context).load(provinceEntity.getCompLogo()).apply(optionsOrganization).into(logo);
            tag.setText("政府");
            tag.setTextColor(context.getResources().getColor(R.color.color_secondary_purple));
            tag.setBackground(context.getResources().getDrawable(R.drawable.shape_rd2_str1_purple_bg));
        }

    }
}
